import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import { Link } from 'dva/router';
import {
  Table,
  Card,
} from 'antd';

import PageHeaderLayout from '../../../layouts/PageHeaderLayout';

@connect(({ risk }) => ({
  risk,
}))
export default class PreCheckList extends PureComponent {
  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'risk/getTaskList',
      payload: {
        offset: 0,
        limit: 10,
        taskState: 1,
        taskCode: 'chushai',
      },
    });
  }

  tableColumns = [
    { title: '业务编号', dataIndex: 'bizNum', key: 'bizNum' },
    { title: '客户姓名', dataIndex: 'custName', key: 'custName' },
    { title: '创建时间', dataIndex: 'createTime', key: 'createTime' },
    {
      title: '操作',
      render: (text, reacd) => (
        <Fragment>
          <Link to={`/risk/preCheckDetail?id=${reacd.id}&taskId=${reacd.taskId}`}>详情</Link>
        </Fragment>
      ),
    },
  ];

  handleStandardTableChange = e => {
    this.props.dispatch({
      type: 'risk/getTaskList',
      payload: {
        offset: (e.current - 1) * e.pageSize,
        limit: e.pageSize,
        taskState: 1,
        taskCode: 'chushai',
      },
    });
  };

  render() {
    const { risk: { riskTaskList, riskPage, riskLoading } } = this.props;
    return (
      <PageHeaderLayout title="业务初筛">
        {/* {JSON.stringify(riskTaskList)} */}
        <Card>
          <Table
            rowKey="id"
            loading={riskLoading}
            pagination={riskPage}
            dataSource={riskTaskList}
            columns={this.tableColumns}
            onChange={this.handleStandardTableChange}
          />
        </Card>
      </PageHeaderLayout>
    );
  }
}
